import sys

def get_q30(infile,outfile):
    data_sum = 0
    all_sum = 0
    with open(infile) as file:
        n = 0
        for line in file:
            if line.startswith('#Quality'):
                n = 1
                continue       
            if n == 1:
                if line.startswith('>>END_MODULE'):
                    break
                else:
                    all_sum += float(line.split()[1])
                    if int(line.split()[0]) >= 30:
                        data_sum += float(line.split()[1])   
    sampleid = outfile.strip().split('/')[-1].split('.')[0]
    with open(outfile,'w') as out:        
        a = data_sum*100/all_sum
        out.write(f'{sampleid}\t{a:.2f}\n')

if __name__ == "__main__":
    inputfile = sys.argv[1]
    outputfile = sys.argv[2]
    get_q30(inputfile,outputfile)
